﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FrmMain;
using System.Data;
using System.Data.SqlClient;

namespace medio
{
    class Service
    {
        Dao dao = new Dao();
        List<songEntity> songlist = new List<songEntity>();
        public List<songEntity> GetSongList()
        {
            string sql = "select * from song_info";
            DataTable table = dao.GetTable(sql,null);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                songEntity entity = new songEntity();
                entity.Id =Convert.ToInt32( table.Rows[i]["song_id"]);
                entity.Ab =Convert.ToString( table.Rows[i]["song_ab"]);
                entity.WordCount = Convert.ToInt32(table.Rows[i]["song_word_count"]);
                entity.TypeId = Convert.ToInt32(table.Rows[i]["songtype_id"]);
                entity.SingerId = Convert.ToInt32(table.Rows[i]["singer_id"]);
                entity.SongUrl = Convert.ToString(table.Rows[i]["song_url"]);
                entity.PlayCount = Convert.ToInt32(table.Rows[i]["song_play_count"]);
                songlist.Add(entity);
            }
            return songlist;
        }

        public string getSongUrl()
        {
            string sql = @"select resource_path from resource_path where resource_id=1";
            string url =Convert.ToString( dao.DoScalar(sql));

            return url;

        }

        public bool setUrl(string str)
        {
            string sql = "  update resource_path set resource_path =@str where resource_id =1";
            SqlParameter[] parame = { new SqlParameter("@str", str) };
            if (dao.DoNonquery(sql, parame) > 0) {
                return true;
            }
            return false;
        }
    }
}
